<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
	<head lang="en">
		<meta charset="UTF-8">
		<title>淘淘书城首页</title>
		<link rel="stylesheet" type="text/css"  th:href="@{/dist/css/bootstrap.min.css}">
		<link rel="stylesheet" type="text/css" th:href="@{/css/index.css}" />
		<link rel="stylesheet" type="text/css" th:href="@{/css/animate.css}" />
	</head>

	<body>
		<!--导航部分  begin-->
		<div th:replace="common/bookAll::header"></div>
		<!--导航部分 end-->

		<!--最顶端轮播图片 begin-->
		<div th:replace="common/bookAll::carousel"></div>
		<!--最顶端轮播图片 end-->

		<!--图书内容部分 begin-->
		<div class="container">
			<!--精选图书 begin-->
			<div>
				<div class="text-primary"><img th:src="@{/images/bullet1.gif}" alt="" title="">
					<a href="#">精选图书</a>
				</div>
				<!--加载数据精选图书数据，使用jquery 的 load 方法-->
				<div id="selected"></div>
			</div>
			<!--精选图书 end-->

			<!--推荐图书 begin-->
			<div>
				<div class="text-primary"><img th:src="@{/images/bullet1.gif}" alt="" title="">
					<a href="#">推荐图书</a>
				</div>
				<div id="recommend"></div>
			</div>
			<!--推荐图书end..-->

			<!--特价图书 begin-->
			<div>
				<div class="text-primary"><img th:src="@{/images/bullet1.gif}" alt="" title="">
					<a href="#">特价图书</a>
				</div>
				<div id="bargain"></div>
			</div>
			<!--特价图书 end-->
			<hr>
			<!--首页底部信息 begin-->
			<div th:replace="common/bookAll::footer"></div>
		</div>
		<!--首页底部信息end-->
		<!--图书内容部分end-->

		<!-- 登录模态框（Modal） -->
		<!-- 注册模态框-->
		<div th:replace="common/bookModal::bookModal"></div>
		
		<script th:src="@{/dist/js/jquery.min.js}"></script>
		<script th:src="@{/js/carousel.js}" type="text/javascript" charset="utf-8"></script>
		<script th:src="@{/dist/js/bootstrap.min.js}"></script>
		<script th:src="@{/js/wow.js}"></script>
		<script th:src="@{/js/login_reg.js}"></script>
		<script th:src="@{/js/sweetalert.min.js}"></script>
		<script th:inline="javascript">
			//获取网站的虚拟路径
			var contextPath = [[${#request.getContextPath()}]];
		</script>
		<script type="text/javascript">
			if(!(/msie [6|7|8|9]/i.test(navigator.userAgent))) {
				new WOW().init();
			}

			/*加载精选图书中的局部图书中的数据*/
			$(function () {
				$('#selected').load(contextPath + "/book/getBookData",buildQuery(1,1))
				$('#recommend').load(contextPath + "/book/getBookData",buildQuery(1,2))
				$('#bargain').load(contextPath + "/book/getBookData",buildQuery(1,3))
			})
			//精选图书的分页按钮的实现
			function loadData(page,category) {
				var node;
				if (category === 1){
					node = "selected";
				}else if(category === 2){
					node = "recommend";
				}else {
					node = "bargain"
				}
				$('#' + node).load(contextPath + "/book/getBookData",buildQuery(page,category))
			}

			//包装分页的页码数据，page 为页码，category 为图书的类别
			function buildQuery(page,category) {
				var query = {}
				//默认为第一页
				query.page = typeof page == "undefined" ? 1: page;
				query.category = category;
				return query;
			}
			
			/*//验证用户名是否已经存在
			function checkUserName(obj) {
				if (obj.value === "" || obj.value == undefined){
					$('#msg').css("display","block");
					$('#msgTitle').html("用户名不合法").removeClass("alert-success").addClass("alert-danger");
					$('#regBtn').addClass("disabled")
					return false;
				}else {
					$.ajax({
						url: contextPath + "/user/checkUserName",
						method: "post",
						data: {"username":obj.value},
						success: function (data) {
							$('#msg').css("display","block");
							if (data === "102"){//用户存在
								$('#msgTitle').html("用户名已被注册").removeClass("alert-success").addClass("alert-danger");
								$('#regBtn').addClass("disabled")
							} else {
								$('#msgTitle').html("用户名可以注册").removeClass("alert-danger").addClass("alert-success");
								$('#regBtn').removeClass("disabled")
								// $('#msgTitle').removeClass("alert-danger");
								// $('#msgTitle').addClass("alert-info");
								return true;
							}
						}
					})
					return true;
				}
			}

			//密码和空字段的校验
			function checkPassword() {
				var pwd = $('#pwd').val();
				var rePwd = $('#rePwd').val();

				if (pwd == "" || pwd == undefined || pwd != rePwd){
					$('.pwd').show();
					return false;
				}else {
					$('.pwd').hide();
					return true;
				}
			}

			function checkNull(){
				var email = $('#email').val();
				var phone = $('#phone').val();
				var company = $('#company').val();
				if (email == "" || email == undefined || phone == "" || phone == undefined || company == "" || company == undefined){
					alert("请填写完整的信息")
					return false;
				}else {
					var reg = /\w+[@]{1}\w+[.]\w+/;
					if (!reg.test(email)){
						alert("请输入正确的email！");
						$("#email").focus();
						return false;
					}
					var reg = /^1[345789]\d{9}$/;
					if (!reg.test(phone)){
						alert("请输入正确的手机号！");
						$("#phone").focus();
						return false;
					}
					return true;
				}
			}

			//用户注册
			function register() {
				if (!checkUserName($('#regName')[0]) || !checkPassword() || !checkNull()){
					return;
				}
				else  {
					$.ajax({
						url: contextPath + "/user/register",
						method: "post",
						data: $("#regForm").serialize(),
						success: function (data) {
							if (data === "success"){
								alert("注册成功，请登录")
							}
							$("#registerModel").modal("hide");
						}
					})
				}

			}

			//用户登录
			function login(){
				var datas = $("#loginForm").serialize();
				$.ajax({
					url: contextPath + "/user/login",
					method: "post",
					data: datas,
					success: function (data) {
						$('#noUser').css("display","none");
						$('#errorPwd').css("display","none");
						if (data === "100"){
							$("#loginModal").modal("hide");
							alert("登录成功")
							window.location.href = contextPath + "/book/index";
						}else if (data == "101"){
							$('#noUser').css("display","block");
						}else {
							$('#errorPwd').css("display","block");
						}
					}
				})
			}*/


		</script>


	</body>

</html>